package com.gt.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gt.app.common.ColonoscopyEnum;
import com.gt.app.domain.EsCheckReport;
import com.gt.app.domain.EsColonoscopyCheckSymptom;
import com.gt.app.domain.EsOperationAfterInfo;
import com.gt.app.domain.dto.EsCheckReportDto;
import com.gt.app.domain.dto.EsOperationAfterInfoDto;
import com.gt.app.mapper.EsOperationAfterInfoMapper;
import com.gt.app.service.EsColonoscopyCheckSymptomService;
import com.gt.app.service.EsOperationAfterInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 术后信息表 服务实现类
 * </p>
 *
 * @author caidesheng
 */
@Slf4j
@Service
public class EsOperationAfterInfoServiceImpl extends ServiceImpl<EsOperationAfterInfoMapper, EsOperationAfterInfo> implements EsOperationAfterInfoService {

    @Autowired
    private EsColonoscopyCheckSymptomService esColonoscopyCheckSymptomService;

    @Override
    public List<EsOperationAfterInfoDto> getOneDayById(String checkId,String type) {
        List<EsOperationAfterInfoDto> operationAfterInfoDtoList = new ArrayList<>();
        LambdaQueryWrapper<EsOperationAfterInfo> eq = new LambdaQueryWrapper<EsOperationAfterInfo>().eq(EsOperationAfterInfo::getEsCheckId, checkId).eq(EsOperationAfterInfo::getType,type);
        List<EsOperationAfterInfo> operationAfterInfos = this.list(eq);
        if (operationAfterInfos == null){
            return null;
        }
        for (EsOperationAfterInfo operationAfterInfo : operationAfterInfos) {
            EsOperationAfterInfoDto operationAfterInfoDto = new EsOperationAfterInfoDto();
            BeanUtils.copyProperties(operationAfterInfo, operationAfterInfoDto);
            LambdaQueryWrapper<EsColonoscopyCheckSymptom> wapper = new LambdaQueryWrapper<EsColonoscopyCheckSymptom>().eq(EsColonoscopyCheckSymptom::getCloOrdrowid, operationAfterInfo.getOrdrowid());
            List<EsColonoscopyCheckSymptom> list = esColonoscopyCheckSymptomService.list(wapper);

            List<String> lesionSiteItem = new ArrayList<>();
            List<String> pathologyLesionItem = new ArrayList<>();
            List<String> pathologyIncreaseItem = new ArrayList<>();

            for (EsColonoscopyCheckSymptom esColonoscopyCheckSymptom : list) {
                if (ColonoscopyEnum.LESION_SITE.getName().equals(esColonoscopyCheckSymptom.getType())) {
                    lesionSiteItem.add(esColonoscopyCheckSymptom.getItem());
                }
                if (ColonoscopyEnum.PATHOLOGY_LESION.getName().equals(esColonoscopyCheckSymptom.getType())) {
                    pathologyLesionItem.add(esColonoscopyCheckSymptom.getItem());
                }
                if (ColonoscopyEnum.PATHOLOGY_INCREASE.getName().equals(esColonoscopyCheckSymptom.getType())) {
                    pathologyIncreaseItem.add(esColonoscopyCheckSymptom.getItem());
                }
            }
            operationAfterInfoDto.setLesionSiteItem(lesionSiteItem);
            operationAfterInfoDto.setPathologyLesionItem(pathologyLesionItem);
            operationAfterInfoDto.setPathologyIncreaseItem(pathologyIncreaseItem);
            operationAfterInfoDtoList.add(operationAfterInfoDto);
        }
        return operationAfterInfoDtoList;
    }
}
